package com;
import com.mapper.Employee;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.testng.annotations.Test;

public class EmployeeTest {
    @Test
    public void findEmployeeBIdTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Employee employee = sqlSession.selectOne("selectByPrimaryKey", 3);
        sqlSession.commit();
        sqlSession.close();
        System.out.println(employee.toString());

    }

    @Test
    public void addEmployeeTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Employee employee = new Employee();

        employee.setId(4);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");

        int addInt = sqlSession.insert("insert", employee);
        sqlSession.commit();
        sqlSession.close();
        System.out.println(addInt);

    }

    @Test
    public void updateEmployeeTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Employee employee = new Employee();

        employee.setId(2);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");

        int u = sqlSession.insert("updateByPrimarykey", employee);
        sqlSession.commit();
        sqlSession.close();
        System.out.println(u);
    }
    @Test
    public void deleteEmployeeById{
        SqlSession sqlSession = MyBatisUtils.getSession();
        int d = sqlSession.insert("deleteByPrimaryKey", employee);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
        System.out.println(d);
    }
}
